import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import HomeIndex from '../views/admin/AdminIndex.vue' //首页
//商品
import ProductList from '../views/admin/commodity/ProductList.vue'  //商城列表
import ProductAdd from '../views/admin/commodity/ProductAdd.vue'  //添加商品
import ProductType from '../views/admin/commodity/ProductType.vue'  //商品分类
// import ProductBrand from '../views/admin/commodity/ProductBrand.vue'  //商品品牌
import ProductSpecs from '../views/admin/commodity/ProductSpecs.vue'  //商品规格
import Purchase from '../views/admin/commodity/Purchase.vue'  //商品采购
import Supplier from '../views/admin/commodity/Supplier.vue' //供应商管理
// 订单
import OrderList from '../views/admin/order/OrderList.vue'  //订单列表
import ReturnGoods from '../views/admin/order/ReturnGoods.vue'  //退货申请处理
import ReturnReason from '../views/admin/order/ReturnReason.vue'  //退货原因设置
// 营销
import SlideShow from '../views/admin/marketing/SlideShow.vue'  //商品轮播图
// 权限
import AdminList from '../views/admin/limits/AdminList.vue'  //管理员列表
import UserList from '../views/admin/limits/UserList.vue'  //顾客列表
import RoleList from '../views/admin/limits/RoleList.vue'  //角色列表
// 登录于注册
import Login from '../views/login/login.vue'
import loginForm from '../views/login/Login_Form.vue'
import registerForm from '../views/login/register_form.vue'
import forgotPassword from '../views/login/ForgotPassword'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: () => {
      try {
        let store = JSON.parse(localStorage.getItem("roles"));
        console.log(store);
        if (store == '顾客' || store == null) {
          return '/MallHome'
        } else {
          return '/MallHome'
        }
      } catch (e) {
        return '/MallHome'
      }
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    children: [
      {
        path: '/loginForm',
        name: '登录',
        component: loginForm
      },
      {
        path: '/registerForm',
        name: '注册',
        component: registerForm
      }, {
        path: '/forgotPassword',
        name: '找回密码',
        component: forgotPassword
      },
    ]
  },
  {
    path: '/home',
    name: 'Home',
    component: HomeView,
    children: [
      {
        path: '/HomePage',
        name: '首页',
        component: HomeIndex,
        meta: {
          requiresAuth: true,
        }
      },
      {
        path: '/MallHome',
        name: '商城首页',
        component: () => import("@/views/user/MallHome")
      },
      {
        path: '/MallProduct',
        name: '商城商品',
        component: () => import("@/views/user/MallProduct")
        , meta: {
          headerName: [
            { name: '商城商品' }]
        }
      },
      {
        path: '/shoppingCart',
        name: '购物车',
        component: () => import("@/views/user/ShoppingCart.vue"),
        meta: {
          requiresAuth: true,
          headerName: [{ name: '购物车' }]
        }
      },
      {
        path: '/MyOrder',
        name: '我的订单',
        component: () => import("@/views/user/MyOrder"),
        meta: {
          requiresAuth: true,
          headerName: [{ name: '我的订单' }]
        }
      },
      {
        path: '/cake',
        name: '全部',
        meta: {
          requiresAuth: true,
        },
        component: () => import("@/views/user/cake/cake.vue"),
      },
      {
        path: '/collect',
        name: '全部',
        meta: {
          requiresAuth: true,
        },
        component: () => import("@/views/user/collect_Product.vue")
      }
      ,
      {    //商品列表
        path: '/ProductList',
        name: '商品列表',
        component: ProductList,
        meta: {
          requiresAuth: true,
          headerName: [
            { name: '商品', url: '/ProductList' },
            { name: '商品列表' }]
        }
      }, { //添加商品
        path: '/ProductAdd',
        name: '添加商品',
        component: ProductAdd,
        meta: {
          requiresAuth: true,
          // productRole: true,
          headerName: [
            { name: '商品', url: '/ProductList' },
            { name: '添加商品' }]
        }
      }, { //商品类别
        path: '/ProductType',
        name: '商品类别',
        component: ProductType,
        meta: {
          requiresAuth: true,
          // productRole: true,
          headerName: [
            { name: '商品', url: '/ProductList' },
            { name: '商品类别' }]
        }
      }, { //商品品牌
        path: '/ProductBrand',
        name: '商品说明',
        component: () => import("@/views/admin/commodity/ProductExplain"),
        meta: {
          requiresAuth: true,
          // productRole: true,
          headerName: [
            { name: '商品', url: '/ProductList' },
            { name: '商品说明' }]
        }
      }, { //商品规格
        path: '/ProductSpecs',
        name: '商品规格',
        component: ProductSpecs,
        meta: {
          requiresAuth: true,
          // productRole: true,
          headerName: [
            { name: '商品', url: '/ProductList' },
            { name: '商品规格' }]
        }
      }, { //商品采购
        path: '/Purchase',
        name: '商品采购',
        component: Purchase,
        meta: {
          requiresAuth: true,
          // productRole: true,
          headerName: [
            { name: '商品', url: '/ProductList' },
            { name: '商品采购' }]
        }
      }, { //供应商
        path: '/Supplier',
        name: '供应商管理',
        component: Supplier,
        meta: {
          requiresAuth: true,
          // productRole: true,
          headerName: [
            { name: '商品', url: '/ProductList' },
            { name: '供应商管理' }]
        }
      }, { //订单列表列表
        path: '/OrderList',
        name: '订单列表',
        component: OrderList,
        meta: {
          requiresAuth: true,
          // orderRole: true,
          headerName: [
            { name: '订单', url: '/OrderList' },
            { name: '订单列表' }]
        }
      }
      // ,
      // { //订单详情
      //   path: '/OrderDetail',
      //   name: '订单详情',
      //   component: OrderDetail,
      //   meta: {
      //     requiresAuth: true,
      //     orderRole: true,
      //     headerName: [
      //       { name: '订单', url: '/OrderList' },
      //       { name: '订单详情' }]
      //   }
      // }
      , { //退货原因
        path: '/ReturnReason',
        name: '退货原因设置',
        component: ReturnReason,
        meta: {
          requiresAuth: true,
          // orderRole: true,
          headerName: [
            { name: '订单', url: '/OrderList' },
            { name: '退货原因设置' }]
        }
      }, { //商品退货
        path: '/ReturnGoods',
        name: '退货申请处理',
        component: ReturnGoods,
        meta: {
          requiresAuth: true,
          // orderRole: true,
          headerName: [
            { name: '订单', url: '/OrderList' },
            { name: '退货申请处理' }]
        }
      }, { //商品轮播图
        path: '/SlideShow',
        name: '商品轮播图',
        component: SlideShow,
        meta: {
          requiresAuth: true,
          // orderRole: true,
          headerName: [
            { name: '营销', url: '/SlideShow' },
            { name: '商品轮播图' }]
        }
      }, { //管理员列表
        path: '/AdminList',
        name: '管理员列表',
        component: AdminList,
        meta: {
          requiresAuth: true,
          // userRole: true,
          headerName: [
            { name: '权限', url: '/AdminList' },
            { name: '用户列表' }]
        }
      }, { //顾客列表
        path: '/UserList',
        name: '用户列表',
        component: UserList,
        meta: {
          requiresAuth: true,
          // userRole: true,
          headerName: [
            { name: '权限', url: '/UserList' },
            { name: '用户列表' }]
        }
      }, { //角色列表
        path: '/RoleList',
        name: '角色列表',
        component: RoleList,
        meta: {
          requiresAuth: true,
          // userRole: true,
          headerName: [
            { name: '权限', url: '/UserList' },
            { name: '角色列表' }]
        }
      }
      , { //个人中心
        path: '/personalCenter',
        name: '个人中心',
        component: () => import("@/views/user/PersonalCenter"),
        meta: {
          requiresAuth: true,
          headerName: [{ name: '个人中心' }]
        }
      }
      , { //修改密码
        path: '/changePassword',
        name: '修改密码',
        component: () => import("@/views/login/ForgotPassword"),
        meta: {
          requiresAuth: true,
          headerName: [{ name: '修改密码' }]
        }
      }
      , {
        path: '/NoAccess',
        name: '暂无权限访问',
        component: () => import("../views/admin/marketing/show")
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
